﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace IOTest
{
    public class IOHelper
    {
        public static void Writer(string path, string fileName, string content)
        {
            byte[] bytes = null;//内容转字节

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            using (var writer = new FileStream(path + "\\" + fileName, FileMode.OpenOrCreate, FileAccess.Write))
            {
                bytes = Encoding.UTF8.GetBytes(content);
                writer.Write(bytes, 0, bytes.Length);

            }
        }

        public static void Reader(string path)
        {
            byte[] bytes = null;// 内容转字节
            string content = string.Empty;//内容

            using (var reader = new FileStream(path,FileMode.Open,FileAccess.Read))
            {
                var length = (int)reader.Length;
                bytes = new byte[length];
                reader.Read(bytes, 0, length);
                content = Encoding.UTF8.GetString(bytes);
                
            }
            Console.Write(content);

        }
    }
}
